package evolutionaryLoop.selectionMechanisme;

import java.util.ArrayList;
import java.util.Collections;

import evolutionaryLoop.Population;

public class RankSelection extends GlobalSelectionMechanisme{
	
	public RankSelection(){
	}

	@Override
	public void setPopulation(Population population) {
		phenotypeList = population.getPopulationList(); 
		scaledFitnessList = new ArrayList<Double>(phenotypeList.size());
		Collections.sort(phenotypeList); 
		double totalRank = 0.5*phenotypeList.size()*(phenotypeList.size()+1); 
		for (int i = 0; i < phenotypeList.size(); i++){
			scaledFitnessList.add((i+1)/totalRank); 
		}
		
	}
	
	public String toString(){
		return "Rank selection"; 
	}

}
